package com.ohuang.login

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.ohuang.base.AuthInterceptorOkHttpClient
import com.ohuang.base.User
import com.ohuang.login.ui.theme.HiltTheme
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.OkHttpClient
import okhttp3.Request
import javax.inject.Inject

@AndroidEntryPoint
class LoginActivity : ComponentActivity() {
    val TAG = "LoginActivity"

    @Inject
    lateinit var okHttpClient: LoginAnalyticsAdapter
    @Inject
    lateinit var user: User
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        okHttpClient.okHttpClient.newCall(
            request = Request.Builder().url("http://www.baidu.com").build()
        )
        Log.d(TAG, "onCreate: " + okHttpClient.okHttpClient)
        Log.d(TAG, "onCreate: " + user)
        setContent {
            HiltTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
   Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    HiltTheme {
        Greeting("Android")
    }
}